package com.qmx.launcher.adapter;

import android.annotation.SuppressLint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.open.androidtvwidget.leanback.adapter.GeneralAdapter;
import com.open.androidtvwidget.leanback.mode.OpenPresenter;
import com.qmx.launcher.R;
import com.qmx.launcher.activity.FileDialogFragment;
import com.qmx.launcher.bean.ContactModel;
import com.qmx.launcher.utils.DateTimeUtils;

import io.realm.OrderedRealmCollection;

/**
 * @author ChengXiangtong
 * @create 2018/11/12
 * @Describe
 */
public class FileRecyclerViewPresenter extends OpenPresenter {

    private final OrderedRealmCollection<ContactModel> contactModels;
    private GeneralAdapter mAdapter;
    private int currentPosition;


    public FileRecyclerViewPresenter(OrderedRealmCollection<ContactModel> contactModels1) {
        this.contactModels = contactModels1;
    }

    @Override
    public void setAdapter(GeneralAdapter adapter) {
        this.mAdapter = adapter;
    }


    @Override
    public int getItemCount() {
        return contactModels.size();
    }

    @Override
    public int getItemViewType(int position) {
        return 0;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_file_group, parent, false);
        return new GridViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder viewHolder, int position) {
        //        GridViewHolder gridViewHolder = (GridViewHolder) viewHolder;
        //        TextView tv_contact_number = gridViewHolder.tv_contact_number;
        //        TextView tv_contact_date = gridViewHolder.tv_contact_date;
        //        TextView tv_contact_name = gridViewHolder.tv_contact_name;
        //        ((GridViewHolder) viewHolder).tv_contact_name.setOnClickListener(new View.OnClickListener() {
        //            @Override
        //            public void onClick(View view) {
        //
        //            }
        //        });

        ((GridViewHolder) viewHolder).tv_contact_name.setText(contactModels.get(position).getName());
        //DateTimeUtils.getNow(DateTimeUtils.FORMAT_FULL)
        ((GridViewHolder) viewHolder).tv_contact_number.setText(contactModels.get(position).getMobile() + "");
        ((GridViewHolder) viewHolder).tv_contact_date.setText("打开");
        System.err.println("onBindViewHolder===" + position);
        //        DateTimeUtils.format(contactModels.get(position).getMdate(), DateTimeUtils.FORMAT_LONG)
        //        viewHolder.view.setFocusable(true);
        ((GridViewHolder) viewHolder).tv_contact_name.setTag(position);
        //        ((GridViewHolder) viewHolder).tv_contact_name.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        //            @SuppressLint("ResourceAsColor")
        //            @Override
        //            public void onFocusChange(View v, boolean hasFocus) {
        //                Log.i("adapter", "hasfocus:" + position + "--" + hasFocus);
        //                //                TextView tv_contact_name2 = v.findViewById(R.id.tv_contact_name);
        //                //                if (hasFocus) {
        //                //                    ((GridViewHolder) viewHolder).tv_contact_name.setFocusable(hasFocus);
        //                //                } else {
        //                //                    ((GridViewHolder) viewHolder).tv_contact_name.setFocusable(false);
        //                //                }
        //            }
        //        })

        //
    }


    public class GridViewHolder extends ViewHolder {

        public TextView tv_contact_name;
        public TextView tv_contact_number;
        public TextView tv_contact_date;

        public GridViewHolder(View itemView) {
            super(itemView);
            tv_contact_name = (TextView) itemView.findViewById(R.id.tv_contact_name);
            tv_contact_number = (TextView) itemView.findViewById(R.id.tv_contact_number);
            tv_contact_date = (TextView) itemView.findViewById(R.id.tv_contact_date);


        }

    }
}
